<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="报表年份" prop="reportYear">
        <el-date-picker :editable="false" clearable v-model="queryParams.reportYear" type="monthrange"
          range-separator="至" start-placeholder="开始月份" end-placeholder="结束月份" value-format="yyyy-MM">
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="报表编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入报表编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!--  <el-form-item label="报表名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入报表名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批准人" prop="pzr">
        <el-input
          v-model="queryParams.pzr"
          placeholder="请输入批准人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人" prop="shrPerson">
        <el-input
          v-model="queryParams.shrPerson"
          placeholder="请输入审核人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="编制" prop="bz">
        <el-input
          v-model="queryParams.bz"
          placeholder="请输入编制"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['productionProcess:analysis_cost:add']">新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['productionProcess:analysis_cost:edit']"
          >修改</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['productionProcess:analysis_cost:remove']">删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['productionProcess:analysis_cost:export']"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-s-check" size="mini" :disabled="multiple" @click="handleCheck"
          v-hasPermi="['productionProcess:analysis_cost:check']">审核</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="analysis_costList" @selection-change="handleSelectionChange" max-height="550">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" width="100px" />
      <el-table-column label="报表年份" align="center" prop="reportYear" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportYear, "{y}-{m}-{d}") }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="报表编号" align="center" prop="code" />
      <!--      <el-table-column label="报表名称" align="center" prop="name" />-->
      <!--      <el-table-column label="批准人" align="center" prop="pzr" />-->
      <el-table-column label="审核人" align="center" prop="shrPerson" />
      <el-table-column label="编制人" align="center" prop="bz" />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="250px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="excelhandleView(scope.row)">导出</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['productionProcess:analysis_cost:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['productionProcess:analysis_cost:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改仰口生产基地费用统计对话框 -->

    <el-dialog fullscreen :title="title" :visible.sync="open" width="900px" append-to-body custom-class="myDialog">
      <TableHeader @nameChange="nameChange" :data="{
          mainTitle: '仰口生产基地费用统计表',
          company: '青岛崂山矿泉水有限公司',
          code: form.code,
        }" />
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="报表年份" prop="reportYear">
              <el-date-picker :editable="false" clearable v-model="form.reportYear" type="year" value-format="yyyy"
                placeholder="选择报表年份" :disabled="openDisabled" @change="anew">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!--  <el-col :span="12">
            <el-form-item label="报表编号" prop="code">
              <el-input
                v-model="form.code"
                placeholder="请输入报表编号"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报表名称" prop="name">
              <el-input
                v-model="form.name"
                placeholder="请输入报表名称"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col> -->

          <!-- <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="openDisabled" />
            </el-form-item>
          </el-col> -->
        </el-row>
        <br />
        <el-divider content-position="center">仰口生产基地费用统计子信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddRptAnalysisCostRecordSub"
              :disabled="open2">生成</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-delete
              " size="mini" @click="handleAddRptAnalysisCostRecordSubDel"
              :disabled="checkedRptAnalysisCostRecordSub.length==0">删除</el-button>
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteRptAnalysisCostRecordSub"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col> -->
        </el-row>
        <el-table max-height="550" :data="rptAnalysisCostRecordSubList"
          :row-class-name="rowRptAnalysisCostRecordSubIndex"
          @selection-change="handleRptAnalysisCostRecordSubSelectionChange" ref="rptAnalysisCostRecordSub"
          :span-method="objectSpanMethod" fit>
          <el-table-column type="selection" width="50" align="center" />
          <!-- <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          /> -->
          <el-table-column label="报表月份" prop="month">
            <template slot-scope="scope">
              <!-- <el-input v-model="scope.row.month" placeholder="请输入报表月份" :disabled="openDisabled" /> -->
              <el-select v-model="scope.row.month" placeholder="请选择报表月份" :disabled="openDisabled">
                <el-option value="1">1</el-option>
                <el-option value="2">2</el-option>
                <el-option value="3">3</el-option>
                <el-option value="4">4</el-option>
                <el-option value="5">5</el-option>
                <el-option value="6">6</el-option>
                <el-option value="7">7</el-option>
                <el-option value="8">8</el-option>
                <el-option value="9">9</el-option>
                <el-option value="10">10</el-option>
                <el-option value="11">11</el-option>
                <el-option value="12">12</el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="费用项目" prop="fyxm" minWidth="100">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fyxm" placeholder="请输入费用项目" :disabled="openDisabled||scope.row.month=='合计'" />
            </template>
          </el-table-column>
          <el-table-column label="生产耗用" header-align="center">
            <el-table-column label="产量" prop="cl" minWidth="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.cl" placeholder="请输入" :disabled="openDisabled||scope.row.month=='合计'" type="number"
                  @input="output(scope)" />
              </template>
            </el-table-column>
            <el-table-column label="数量(千瓦时/吨/升)" prop="sl1" minWidth="120">
              <template slot-scope="scope">
                <el-input v-model="scope.row.sl1" placeholder="请输入" :disabled="openDisabled||scope.row.month=='合计'" @input="calculate2(scope)"
                  type="number" />
              </template>
            </el-table-column>
            <el-table-column label="金额" prop="je1" minWidth="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.je1" placeholder="请输入" :disabled="openDisabled||scope.row.month=='合计'" @input="calculate(scope)"
                  type="number" />
              </template>
            </el-table-column>
            <el-table-column label="吨水耗用" prop="dshy" minWidth="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.dshy" placeholder="请输入" :disabled="openDisabled||scope.row.month=='合计'" type="number"
                  @input="water(scope)" />
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="其他耗用" header-align="center">
            <el-table-column label="数量(千瓦时/吨/升)" prop="sl2" minWidth="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.sl2" placeholder="请输入" :disabled="openDisabled||scope.row.month=='合计'" @input="calculate2(scope)"
                  type="number" />
              </template>
            </el-table-column>
            <el-table-column label="金额" prop="je2" minWidth="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.je2" placeholder="请输入" :disabled="openDisabled||scope.row.month=='合计'" @input="calculate(scope)"
                  type="number" />
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="合计" header-align="center">
            <el-table-column label="数量" prop="sl3" minWidth="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.sl3" placeholder="请输入" :disabled="true" type="number" />
              </template>
            </el-table-column>
            <el-table-column label="金额" prop="je3" minWidth="100">
              <template slot-scope="scope">
                <el-input v-model="scope.row.je3" placeholder="请输入" :disabled="true" type="number" />
              </template>
            </el-table-column>
          </el-table-column>
          <!--  <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.remark"
                type="textarea"
                placeholder="请输入内容"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column> -->
        </el-table>

        <!-- 审核 -->
        <el-col :span="8">
          <!--          <el-form-item label="批准人" prop="pzr">
            <UserDialog
              @dialogChange="form.pzr = $event.label"
              :echoValue="form.pzr"
              :multiple="false"
              :openDisabled="openDisabled"
              placeholder="请选择人员"
            />-->
          <!-- <el-input
              v-model="form.pzr"
              placeholder="请输入批准人"
              :disabled="openDisabled"
            /> -->
          <!--     <el-select v-model="form.pzr" placeholder="请选择批准人" style="width: 100%" :disabled="openDisabled">
              <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName"></el-option>
            </el-select>-->
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="审核人" prop="shrPerson">
            <el-input v-model="form.shrPerson" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="编制人" prop="bz">
            <UserDialog @dialogChange="form.bz = $event.label" :echoValue="form.bz" :multiple="false"
              :openDisabled="openDisabled" placeholder="请选择人员" />
            <!-- <el-input
              v-model="form.bz"
              placeholder="请输入编制"
              :disabled="openDisabled"
            /> -->
            <!-- <el-select v-model="form.bz" placeholder="请选择编制人" style="width: 100%" :disabled="openDisabled">
              <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName"></el-option>
            </el-select>-->
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listAnalysis_cost,
    getAnalysis_cost,
    delAnalysis_cost,
    addAnalysis_cost,
    updateAnalysis_cost,
    queryList,
    getAnalysis_costMonth,
    checkAnalysis_cost,
  } from "@/api/report/analysis/analysis_cost";
  import { getInfo } from "@/api/login";
  import { listUser } from "@/api/system/user";

  export default {
    name: "Analysis_cost",
    data() {
      return {
        /* 当前用户名 */
        nickName: "",
        userList: [],
        //弹窗是否禁止编辑
        openDisabled: true,
        open2: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 子表选中数据
        checkedRptAnalysisCostRecordSub: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 仰口生产基地费用统计表格数据
        analysis_costList: [],
        // 仰口生产基地费用统计子表格数据
        rptAnalysisCostRecordSubList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 50,
          reportYear: null,
          reportYear1: null,
          code: null,
          name: null,
          pzr: null,
          shrPerson: null,
          bz: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
      };
    },
    created() {
      this.getList();
      this.queryUserList();
    },
    methods: {
      anew() {
        this.open2 = false;
        this.rptAnalysisCostRecordSubList = [];
      },
      /** 查询仰口生产基地费用统计列表 */
      getList() {
        this.loading = true;
        listAnalysis_cost(this.queryParams).then((response) => {
          this.analysis_costList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          reportYear: null,
          code: "LK-QF-LS1-10-013-12-01",
          name: null,
          pzr: this.nickName,
          shrPerson: null,
          bz: this.nickName,
          delFlag: null,
          remark: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
        };
        this.rptAnalysisCostRecordSubList = [];
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;

        if (this.queryParams.reportYear != null) {
          let arr = this.queryParams.reportYear;
          this.queryParams.reportYear = arr[0];
          this.queryParams.reportYear1 = arr[1];
        }
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.id);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.open2 = false;
        this.reset();
        this.openDisabled = false;
        this.open = true;
        this.title = "添加仰口生产基地费用统计";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.openDisabled = false;
        const id = row.id || this.ids;

        // getAnalysis_cost(id).then((response) => {
        //   this.form = response.data;
        //   this.rptAnalysisCostRecordSubList =
        //     response.data.rptAnalysisCostRecordSubList;
        //   this.open = true;
        //   this.title = "修改仰口生产基地费用统计";
        // });
        // console.log(this.form);

        this.queryParams.reportYear = row.reportYear;
        getAnalysis_costMonth(id, this.queryParams).then((response) => {
          this.form = response.data;
          this.rptAnalysisCostRecordSubList =
            response.data.rptAnalysisCostRecordSubList;
          this.open = true;
          this.title = "修改仰口生产基地费用统计";
        });
      },
      /** 查看按钮 */
      handleView(row) {
        this.reset();
        this.openDisabled = true;
        const id = row.id || this.ids;
        getAnalysis_cost(id).then((response) => {
          this.form = response.data;
          this.rptAnalysisCostRecordSubList =
            response.data.rptAnalysisCostRecordSubList;
          this.open = true;
          this.title = "查看仰口生产基地费用统计";
        });
      },
      /** 提交按钮 */
      submitForm() {
        // 合计计算
        // console.log("submit");
        this.totaljs();

        this.$refs["form"].validate((valid) => {
          if (valid) {
            this.form.rptAnalysisCostRecordSubList =
              this.rptAnalysisCostRecordSubList;
            if (this.form.id != null) {
              updateAnalysis_cost(this.form).then((response) => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              const rLoading = this.openLoading();
              addAnalysis_cost(this.form)
                .then((response) => {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  rLoading.close();
                  this.getList();
                })
                .catch((error) => {
                  rLoading.close();
                });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm(
          '是否确认删除仰口生产基地费用统计编号为"' + ids + '"的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(function () {
            return delAnalysis_cost(ids);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(() => { });
      },
      /** 仰口生产基地费用统计子序号 */
      rowRptAnalysisCostRecordSubIndex({ row, rowIndex }) {
        row.index = rowIndex + 1;
      },
      // 金额计算
      calculate(scope) {
        // console.log(scope);
        let obj = this.rptAnalysisCostRecordSubList[scope.$index];
        // 计算吨水
        if (obj.fyxm != "合计") {
          obj.dshy = (Number(scope.row.je1) / Number(obj.cl)).toFixed(2);
        }
        // 金额3
        obj.je3 = (Number(scope.row.je1) + Number(scope.row.je2)).toFixed(2);

        /* 计算合计项 */
        //计算下标
        let index = 5 - ((scope.$index + 1) % 5) + scope.$index;
        this.rptAnalysisCostRecordSubList[index].je1 =
          Number(this.rptAnalysisCostRecordSubList[index - 1].je1) +
          Number(this.rptAnalysisCostRecordSubList[index - 2].je1) +
          Number(this.rptAnalysisCostRecordSubList[index - 3].je1) +
          Number(this.rptAnalysisCostRecordSubList[index - 4].je1);

        this.rptAnalysisCostRecordSubList[index].je2 =
          Number(this.rptAnalysisCostRecordSubList[index - 1].je2) +
          Number(this.rptAnalysisCostRecordSubList[index - 2].je2) +
          Number(this.rptAnalysisCostRecordSubList[index - 3].je2) +
          Number(this.rptAnalysisCostRecordSubList[index - 4].je2);
        this.rptAnalysisCostRecordSubList[index].je3 =
          Number(this.rptAnalysisCostRecordSubList[index - 1].je3) +
          Number(this.rptAnalysisCostRecordSubList[index - 2].je3) +
          Number(this.rptAnalysisCostRecordSubList[index - 3].je3) +
          Number(this.rptAnalysisCostRecordSubList[index - 4].je3);
      },
      calculate2(scope) {
        let obj = this.rptAnalysisCostRecordSubList[scope.$index];
        obj.sl3 = (Number(scope.row.sl1) + Number(scope.row.sl2)).toFixed(2);
        let index = 5 - ((scope.$index + 1) % 5) + scope.$index;
        this.rptAnalysisCostRecordSubList[index].sl1 =
          (Number(this.rptAnalysisCostRecordSubList[index - 1].sl1) +
            Number(this.rptAnalysisCostRecordSubList[index - 2].sl1) +
            Number(this.rptAnalysisCostRecordSubList[index - 3].sl1) +
            Number(this.rptAnalysisCostRecordSubList[index - 4].sl1)).toFixed(2);

        this.rptAnalysisCostRecordSubList[index].sl2 =
          (Number(this.rptAnalysisCostRecordSubList[index - 1].sl2) +
            Number(this.rptAnalysisCostRecordSubList[index - 2].sl2) +
            Number(this.rptAnalysisCostRecordSubList[index - 3].sl2) +
            Number(this.rptAnalysisCostRecordSubList[index - 4].sl2)).toFixed(2)
        this.rptAnalysisCostRecordSubList[index].sl3 =
          (Number(this.rptAnalysisCostRecordSubList[index - 1].sl3) +
            Number(this.rptAnalysisCostRecordSubList[index - 2].sl3) +
            Number(this.rptAnalysisCostRecordSubList[index - 3].sl3) +
            Number(this.rptAnalysisCostRecordSubList[index - 4].sl3)).toFixed(2);
      },
      /* 产量 */
      output(scope) {
        let index = 5 - ((scope.$index + 1) % 5) + scope.$index;
        this.rptAnalysisCostRecordSubList[index].cl =
          (Number(this.rptAnalysisCostRecordSubList[index - 1].cl) +
            Number(this.rptAnalysisCostRecordSubList[index - 2].cl) +
            Number(this.rptAnalysisCostRecordSubList[index - 3].cl) +
            Number(this.rptAnalysisCostRecordSubList[index - 4].cl)).toFixed(2);
      },
      /* 吨水费用 */
      water(scope) {
        let index = 5 - ((scope.$index + 1) % 5) + scope.$index;
        this.rptAnalysisCostRecordSubList[index].dshy =
          (Number(this.rptAnalysisCostRecordSubList[index - 1].dshy) +
            Number(this.rptAnalysisCostRecordSubList[index - 2].dshy) +
            Number(this.rptAnalysisCostRecordSubList[index - 3].dshy) +
            Number(this.rptAnalysisCostRecordSubList[index - 4].dshy)).toFixed(2);
      },
      /* 合计 */
      totaljs() {
        // let temp = this.rptAnalysisCostRecordSubList;
        // console.log(temp);

        // let i = 0;
        // this.rptAnalysisCostRecordSubList.forEach((sub) => {
        //   if (sub.month == "合计") {
        //     i++;
        //   }
        // });

        // if (i == 0) {
        let item = this.rptAnalysisCostRecordSubList.find(item => {
          return item.month == '合计';
        });
        if (item) {
          return false
        }
        const arr = ["电费", "水费", "燃油费", "维修费", "合计"];

        arr.forEach((arr1) => {
          let obj = {};
          obj.month = "合计";
          obj.fyxm = arr1;
          obj.cl = "";
          obj.sl1 = "";
          obj.je1 = "";
          obj.dshy = "";
          obj.sl2 = "";
          obj.je2 = "";
          obj.sl3 = "";
          obj.je3 = "";
          obj.remark = "";
          // 循环赋值
          this.rptAnalysisCostRecordSubList.forEach((sub) => {
            if (sub.fyxm == arr1) {
              obj.cl = (Number(obj.cl) + Number(sub.cl)).toFixed(2);
              obj.sl1 = (Number(obj.sl1) + Number(sub.sl1)).toFixed(2);
              obj.je1 = (Number(obj.je1) + Number(sub.je1)).toFixed(2);
              obj.dshy = (Number(obj.dshy) + Number(sub.dshy)).toFixed(2);
              obj.sl2 = (Number(obj.sl2) + Number(sub.sl2)).toFixed(2);
              obj.je2 = (Number(obj.je2) + Number(sub.je2)).toFixed(2);
              obj.sl3 = (Number(obj.sl3) + Number(sub.sl3)).toFixed(2);
              obj.je3 = (Number(obj.je3) + Number(sub.je3)).toFixed(2);
            }
          });

          this.rptAnalysisCostRecordSubList.push(obj);
        });
        // }
      },
      /** 仰口生产基地费用统计子删除钮操作 */
      handleAddRptAnalysisCostRecordSubDel() {
        this.$confirm(
          '是否确认删除选择的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        ).then(() => {
          let obj = this.checkedRptAnalysisCostRecordSub[0]
          let alls = this.rptAnalysisCostRecordSubList.filter(item => {
            return obj.month.indexOf(item.month) == -1
          })
          this.rptAnalysisCostRecordSubList = alls
        }).catch((er) => {
          console.log(er)
        });
      },
      /** 仰口生产基地费用统计子添加按钮操作 */
      handleAddRptAnalysisCostRecordSub() {
        // console.log(this.rptAnalysisCostRecordSubList);
        // var arry_month=new Array();
        // this.rptAnalysisCostRecordSubList.forEach(element => {
        //   // console.log(element.month);

        //   console.log(element.month);

        //   arry_month.push(Number(element.month));
        // });
        //   const result = Array.from(new Set(arry_month))
        //   console.log(result);
        // return null;

        if (this.form.reportYear != null) {
          // console.log(this.form)
          queryList(this.form).then((res) => {
            res.forEach((item) => {
              console.log(item);
              let obj = {};
              obj.month = item.month;
              /*            obj.cl= item.cl.toFixed(2);
                          obj.fyxm = item.fyxm;
                          obj.sl1=item.sl1;
                          obj.sl3=item.sl3;
                          obj.sl2=item.sl2;
                          obj.je1=item.je1;
                          obj.je2=item.je2;
                          obj.je3=item.je3;
                          obj.dshy=item.dshy;*/
              obj.cl = null;
              obj.fyxm = item.fyxm;
              obj.sl1 = null;
              obj.sl3 = null;
              obj.sl2 = null;
              obj.je1 = null;
              obj.je2 = null;
              obj.je3 = null;
              obj.dshy = null;
              this.rptAnalysisCostRecordSubList.push(obj);
            });

            // console.log(res);
            // res.forEach((item) => {
            //   const arr = ["电费", "水费", "燃油费", "维修费"];
            //   arr.forEach((arr1) => {
            //     let obj = {};
            //     obj.month = item.month;
            //     obj.fyxm = arr1;
            //     if (arr1 != "合计") {
            //       obj.cl = item.ton;
            //     } else {
            //       obj.cl = "";
            //     }
            //     if (arr1 == "电费") {
            //       obj.sl1 = Number(item.electricSy).toFixed(2);
            //     } else if (arr1 == "水费") {
            //       obj.sl1 = Number(item.waterSy).toFixed(2);
            //     } else {
            //       obj.sl1 = "";
            //     }
            //     obj.je2 = "";
            //     if (arr1 == "维修费") {
            //       obj.je1 = item.bjje;
            //       if (Number(item.bjje) != 0) {
            //         obj.dshy = (Number(item.ton) / Number(item.bjje)).toFixed(2);
            //       } else {
            //         obj.dshy = "0";
            //       }
            //       obj.je3 = (Number(obj.je1) + Number(obj.je2)).toFixed(2);
            //     } else {
            //       obj.je1 = "";
            //       obj.dshy = "";
            //       obj.je3 = "";
            //     }

            //     if (arr1 == "电费") {
            //       obj.sl2 = item.qthy;
            //     } else {
            //       obj.sl2 = "";
            //     }

            //     if (arr1 == "电费" || arr1 == "水费") {
            //       obj.sl3 = Number(obj.sl1) + Number(obj.sl2);
            //     } else {
            //       obj.sl3 = "";
            //     }

            //     obj.remark = "";
            //     this.rptAnalysisCostRecordSubList.push(obj);
            //   });
            //   //, "合计"
            //   var obj_sum = {};
            //   obj_sum.month = item.month;
            //   obj_sum.fyxm = "合计";
            //   obj_sum.sl1 = 0;
            //   obj_sum.sl3 = 0;
            //   console.log("obj_sum");
            //   console.log(obj_sum);
            //   for (
            //     let ic = 0;
            //     ic < this.rptAnalysisCostRecordSubList.length;
            //     ic++
            //   ) {
            //     if (
            //       !isNaN(this.rptAnalysisCostRecordSubList[ic].sl1) &&
            //       this.rptAnalysisCostRecordSubList[ic].sl1 != null &&
            //       this.rptAnalysisCostRecordSubList[ic].sl1 != ""
            //     ) {
            //       // console.log(ic);
            //       // console.log(this.rptAnalysisCostRecordSubList[ic].sl1);
            //       obj_sum.sl1 += Number(
            //         this.rptAnalysisCostRecordSubList[ic].sl1
            //       );
            //       // console.log(obj_sum.sl1);
            //     }

            //     if (
            //       !isNaN(this.rptAnalysisCostRecordSubList[ic].sl3) &&
            //       this.rptAnalysisCostRecordSubList[ic].sl3 != ""
            //     ) {
            //       // console.log(ic);
            //       // console.log(this.rptAnalysisCostRecordSubList[ic].sl3);
            //       obj_sum.sl3 += Number(
            //         this.rptAnalysisCostRecordSubList[ic].sl3
            //       );
            //     }
            //   }
            //   this.rptAnalysisCostRecordSubList.push(obj_sum);
            //   // console.log(this.rptAnalysisCostRecordSubList);
            //   // console.log("--");
            // });
            // console.log(this.rptAnalysisCostRecordSubList);
          });
        } else {
          this.msgError("请选择报表年份！");
        }

        // 禁止二次生成
        this.open2 = true;
      },
      /** 仰口生产基地费用统计子删除按钮操作 */
      handleDeleteRptAnalysisCostRecordSub() {
        if (this.checkedRptAnalysisCostRecordSub.length == 0) {
          this.$alert("请先选择要删除的仰口生产基地费用统计子数据", "提示", {
            confirmButtonText: "确定",
          });
        } else {
          this.rptAnalysisCostRecordSubList.splice(
            this.checkedRptAnalysisCostRecordSub[0].index - 1,
            5
          );
        }
      },
      /** 单选框选中数据 */
      handleRptAnalysisCostRecordSubSelectionChange(selection) {
        if (selection.length > 1) {
          this.$refs.rptAnalysisCostRecordSub.clearSelection();
          this.$refs.rptAnalysisCostRecordSub.toggleRowSelection(selection.pop());
        } else {
          this.checkedRptAnalysisCostRecordSub = selection;
        }
      },
      excelhandleView(row) {
        this.download(
          "productionProcess/analysis_cost/exportexcel?id=" + row.id,
          {
            ...this.queryParams,
          },
          "仰口生产基地费用统计" + this.parseTime(new Date()) + ".xlsx"
        );
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "productionProcess/analysis_cost/export",
          {
            ...this.queryParams,
          },
          "仰口生产基地费用统计" + this.parseTime(new Date()) + ".xlsx"
        );
      },
      //接收编号
      nameChange(e) {
        this.form.code = e;
      },
      /* 合并两行 */
      objectSpanMethod({ row, column, rowIndex, columnIndex }) {
        if (columnIndex === 0) {
          if (rowIndex % 5 === 0) {
            return {
              rowspan: 5,
              colspan: 1,
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0,
            };
          }
        }
        if (columnIndex === 1) {
          if (rowIndex % 5 === 0) {
            return {
              rowspan: 5,
              colspan: 1,
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0,
            };
          }
        }
      },
      /** 审核按钮操作 */
      handleCheck(row) {
        /* 审核 */
        this.ids.forEach((id) => {
          getAnalysis_cost(id).then((response) => {
            // console.log(response.data.auditor)
            if (
              response.data.shrPerson != null &&
              response.data.shrPerson != ""
            ) {
              this.msgError(
                '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
              );
            } else {
              let obj = {};
              obj.id = id;
              obj.shrPerson = this.nickName;

              // 子表
              obj.rptAnalysisCostRecordSubList =
                this.rptAnalysisCostRecordSubList;
              /* 修改 */
              checkAnalysis_cost(obj).then((response) => {
                this.msgSuccess('编号为"' + id + '"的数据项审核成功！');
                this.getList();
              });
            }
          });
        });
      },
      /* 查询用户列表 */
      queryUserList() {
        listUser().then((response) => {
          this.userList = response.rows;
        });
        getInfo().then((response) => {
          this.nickName = response.user.nickName;
        });
      },
    },
  };
</script>